package com.zdsoft.blp.zongbuju.shouye.wuye.activity;

import android.content.Intent;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zdsoft.blp.R;
import com.zdsoft.blp.gongyong.API.API;
import com.zdsoft.blp.gongyong.fanhui.FanHuiView;
import com.zdsoft.blp.gongyong.imageFrame.IvFrameView;
import com.zdsoft.blp.gongyong.net.BaseActivity;
import com.zdsoft.blp.gongyong.net.Net;
import com.zdsoft.blp.gongyong.net.NetCallback;
import com.zdsoft.blp.zongbuju.shouye.wuye.entity.XiangQing;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/8/31.
 */
public class WYTongZhiXiangQing extends BaseActivity implements NetCallback{
    private FanHuiView back;
    private TextView tv_ctitle,tv_ctime,tv_ccontent;
    private IvFrameView iv;
    private List<String>list;
    private LinearLayout ll_bk;

    @Override
    protected void init() {
        setContentView(R.layout.wy_tongzhi_xiangqing);
        back=find(R.id.back);
        ll_bk=find(R.id.ll_bk);
        back.getTv_title().setText("详情");
        iv=find(R.id.iv);
        tv_ctitle=find(R.id.tv_ctitle);
        tv_ctime=find(R.id.tv_ctime);
        tv_ccontent=find(R.id.tv_ccontent);
        Intent intent=getIntent();
        String id=intent.getStringExtra("id");

        Net net=new Net();
        net.url= API.GENERALINFO_URL;
        net.nameSpace=API.GENERALINFO_NAMESPACE;
        net.methodName=API.GENERALIFOCONTENT ;
        Map<String,Object> map=new HashMap<>();
        map.put("id",id);
        net.parms=map;
        getServer(net,this);
    }
    @Override
    public void onResponse(boolean flag, int code, String res) {
        ;if (flag){
            String picture="";
            try {
                list=new ArrayList<>();
                JSONObject object=new JSONObject(res);
                String title=object.getString("title");
                String time=object.getString("releaseDate");
                String content=object.getString("content");
                tv_ctitle.setText(title);
                tv_ccontent.setText(Html.fromHtml(content));
                tv_ctime.setText(time);
                JSONArray array=object.getJSONArray("picPathSet");
                for(int j=0;j<array.length();j++){
                    JSONObject object2=array.getJSONObject(j);
                    picture=object2.getString("picPath");
                    list.add(picture);
                }
                if (!picture.equals("")){
                    ll_bk.setVisibility(View.VISIBLE);
                    iv.setVisibility(View.VISIBLE);
                    iv.show(list);
                }else {
                    ll_bk.setVisibility(View.GONE);
                    iv.setVisibility(View.GONE);
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

    }
}
